package com.amigo.online.provider.video.rocketmq.model;


import java.io.Serializable;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.amigo.online.common.param.common.MqTag;

public class BaseMqSendModel implements Serializable {
    private static final long serialVersionUID = -5656703488042160874L;
    @JSONField(serialize = false)
    private String keys;
    private String beanName;
    private String tag;
    private Object sendContentBean;

    /*用了Builder模式，这2个构造不需要了，为了兼容之前，保留*/
    public BaseMqSendModel(String beanName) {
        super();
        this.beanName = beanName;
    }

    public BaseMqSendModel(String beanName, Object sendContentBean) {
        super();
        this.beanName = beanName;
        this.sendContentBean = sendContentBean;
    }
    /*end*/

    public BaseMqSendModel(Builder builder) {
        this.beanName = builder.beanName;
        this.tag = builder.tag;
        this.sendContentBean = builder.sendContentBean;
    }

    public BaseMqSendModel() {
        super();
    }

    public <T> T getSendContentBean(Class<T> clazz) {
        return ((JSONObject) sendContentBean).toJavaObject(clazz);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public String getBeanName() {
        return beanName;
    }

    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }

    public Object getSendContentBean() {
        return sendContentBean;
    }

    public void setSendContentBean(Object sendContentBean) {
        this.sendContentBean = sendContentBean;
    }

    public String getKeys() {
        return keys;
    }

    public void setKeys(String keys) {
        this.keys = keys;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public static class Builder {
        public String beanName;
        public String tag;
        public Object sendContentBean;

        public Builder beanName(String beanName) {
            this.beanName = beanName;
            return this;
        }

        public Builder tag(String tag) {
            this.tag = tag;
            return this;
        }

        public Builder sendContentBean(Object sendContentBean) {
            this.sendContentBean = sendContentBean;
            return this;
        }

        public BaseMqSendModel build() {
            return new BaseMqSendModel(this);
        }

    }

    public static void main(String[] args) {
        BaseMqSendModel baseMqSendModel = new BaseMqSendModel.Builder()
                .tag(MqTag.SEARCH)
                .sendContentBean("testContent")
                .build();
        baseMqSendModel.setKeys("222");
        System.out.println(baseMqSendModel);
        String s = (String) baseMqSendModel.getSendContentBean();
        System.out.println(s);

    }
}
